Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support interpolation in <job>.container.options #1958

Conversation

eliandoran
Copy link
Contributor

Desired functionality

Seems that act does not support variable interpolation in the --device option:

jobs:
  build:
    container:
      options: -uroot --device=${{ inputs.device }}

Results in:

Error: Cannot process container options: '-uroot --device=${{ inputs.device }}': '${{ is not an absolute path'

Seems that variable interpolation is not enabled anywhere in the options field, since it's doing the same for the -u flag:

-u${{inputs.user }}

Results in:

Error: failed to start container: Error response from daemon: unable to find user ${{inputs.user}}: no matching entries in passwd file

These are supported in the live GitHub Actions runner.

Approach

Adapted options method in run_context.go to be in the same style as containerImage which already has support for variable interpolation:

func (rc *RunContext) containerImage(ctx context.Context) string {
	job := rc.Run.Job()

	c := job.Container()
	if c != nil {
		return rc.ExprEval.Interpolate(ctx, c.Image)
	}

	return ""
}

@eliandoran eliandoran requested a review from a team as a code owner August 9, 2023 19:05
@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Merging #1958 (6279709) into master (4989f44) will increase coverage by 0.90%.
Report is 222 commits behind head on master.
The diff coverage is 61.95%.

@@            Coverage Diff             @@
##           master    #1958      +/-   ##
==========================================
+ Coverage   61.22%   62.13%   +0.90%     
==========================================
  Files          46       52       +6     
  Lines        7141     8487    +1346     
==========================================
+ Hits         4372     5273     +901     
- Misses       2462     2795     +333     
- Partials      307      419     +112     
Files Changed Coverage Δ
pkg/common/outbound_ip.go 0.00% <0.00%> (ø)
pkg/container/docker_cli.go 82.23% <ø> (ø)
pkg/container/docker_logger.go 52.08% <ø> (ø)
pkg/container/docker_volume.go 0.00% <0.00%> (ø)
pkg/container/file_collector.go 39.68% <0.00%> (+2.38%) ⬆️
pkg/container/host_environment.go 0.00% <0.00%> (ø)
...ontainer/linux_container_environment_extensions.go 23.07% <0.00%> (-1.25%) ⬇️
pkg/container/util.go 0.00% <0.00%> (ø)
pkg/exprparser/functions.go 66.32% <0.00%> (-1.04%) ⬇️
pkg/container/docker_run.go 13.45% <6.66%> (-0.13%) ⬇️
... and 29 more

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Even keys of container objects can use expressions in actions/runner. I discarded any plans to change the workflow model of act radically to resolve that.

EvaluateYAMLNode has been made to convert a raw yaml.Node into an evaluated / interpolated one, this would also take care of interpolation of all keys and values and would had remove the need to interpolate container options manually.

@eliandoran eliandoran force-pushed the feat/variable_interpolation_in_container_options branch from 47424a6 to 6279709 Compare August 10, 2023 13:18
@cplee cplee merged commit 19764bc into nektos:master Sep 12, 2023
@eliandoran eliandoran deleted the feat/variable_interpolation_in_container_options branch September 13, 2023 05:24
@eliandoran eliandoran restored the feat/variable_interpolation_in_container_options branch September 13, 2023 05:24
@eliandoran eliandoran deleted the feat/variable_interpolation_in_container_options branch September 13, 2023 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants